<?php
namespace App\Http\Controllers\Awards;

use App\Http\Controllers\Controller;
use App\Common\Utils\JsonResponse;
use Illuminate\Http\Request;

class AwardsController extends Controller{


    private $Request;
    private $awardsService;
    private $logService;

    public function __construct(Request $Request)
    {
        parent::__construct();

        /** @var \App\Services\Awards\AwardsService $awardsService */
        $this->awardsService = app('awardsService');
        $this->Request = $Request;
         /** @var \App\Services\System\LogService $logService */
         $this->logService = app('logService');
    }

    /**
     * 获取列表
     * @author lxy
     * @datetime 2023-02-14
     */
    public function getAwardsList()
    {
        try{
            $result = $this->awardsService->getAwardsList($this->Request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 获取参与人
     * @author lxy
     * @datetime 2023-02-17
     */
    public function getParticipantsData()
    {
        try{
            $result = $this->awardsService->getParticipantsData($this->Request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return $this->error($e);
        }
    }

    public function push()
    {
        try{
            $result = $this->awardsService->pushAwards($this->Request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return $this->error($e);
        }
    }

    /**
     * 添加数据
     * @author lxy
     * @datetime 2022-02-17
     */
    public function addAwards()
    {
        try{
            $result = $this->awardsService->addAwards($this->Request->all());
            if(!empty($this->Request->all()['id'])){
                $this->logService->log('177','获奖情况编辑', "获奖情况编辑");
            }else{
                if($this->Request->all()['status'] ==1){
                    $this->logService->log('176','获奖情况提交', "获奖情况提交");
                }else{
                    $this->logService->log('176','获奖情况保存', "获奖情况保存");
                }
            }
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    public function addHonor()
    {
        try{
            $result = $this->awardsService->addHonor($this->Request->all());
            if(!empty($this->Request->all()['id'])){
                $this->logService->log('177','班级荣誉编辑', "班级荣誉编辑");
            }else{
                if($this->Request->all()['status'] ==1){
                    $this->logService->log('176','班级荣誉提交', "班级荣誉提交");
                }else{
                    $this->logService->log('176','班级荣誉保存', "班级荣誉保存");
                }
            }
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }
    /**
     * 获取编辑数据
     * @author lxy
     * @datetime 2023-02-23
     */
    public function getAwardsFirst()
    {
        try{
            $result = $this->awardsService->getAwardsFirst($this->Request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 审核
     * @author lxy
     * @datetime 2023-02-23
     */
    public function checkAwards()
    {
        try{
            $result = $this->awardsService->checkAwards($this->Request->all());
            if($this->Request->all()['status'] == 'PASS'){
                $this->logService->log('178','获奖情况审核通过', "获奖情况审核通过");
            }else{
                $this->logService->log('178','获奖情况审核驳回', "获奖情况审核驳回");
            }
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 删除
     * @author lxy
     * @datetime 2023-02-24
     */
    public function delAwards()
    {
        try{
            $result = $this->awardsService->delAwards($this->Request->all());
            $this->logService->log('180','获奖情况删除', "获奖情况删除");
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 导出
     * @author lxy
     * @datetime 2023-02-24
     */
    public function exportAwards()
    {
        try{
            $result = $this->awardsService->exportAwards($this->Request->all());
            $this->logService->log('332','获奖情况导出', "获奖情况导出");
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 导出
     * @author qiankun
     * @datetime 2023-02-24
     */
    public function exportHonor()
    {
        try{
            $result = $this->awardsService->exportHonor($this->Request->all());
            $this->logService->log('332','班级荣誉导出', "班级荣誉导出");
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 导出
     * @author qiankun
     * @datetime 2023-02-24
     */
    public function importHonor()
    {
        try{
            $result = $this->awardsService->importHonor($this->Request->all());
            $this->logService->log('399','班级荣誉导入', "班级荣誉导入");
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }
}

?>
